﻿using AutoMapper;
using Hotel.Application.Menus.Dto;
using Hotel.Domain;
using Hotel.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.Application.Menus
{
    public class MenuService : BaseService<Menu, MenuCreateUpdateDto, MenuListDto>, IMenuService
    {
        private readonly IRepository<Menu> repository;

        public MenuService(IRepository<Menu> repository) : base(repository)
        {
            this.repository = repository;
        }


        public async Task<List<Menu>> QueryTreeNodesAsync()
        {
            //第三个参数为0 表示 ： parentid为 0 设置成根目录, 正常情况下最顶层的parentid不是0就是null
            var db = repository.GetDbContext();
            var tree = await db.Queryable<Menu>().ToTreeAsync(it => it.Child, it => it.ParentId, 0);
            return tree;
        }
    }
}
